﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HitachiApp.Model;
using HitachiLib.Utils;
using HitachiLib.HitachiServiceRef;

namespace HitachiApp.View
{
    public partial class ScheduleTabView : UserControl
    {
        public ScheduleTabView()
        {
            InitializeComponent();
        }

        private void export_schedule_Click(object sender, RoutedEventArgs e)
        {
            ScheduleTabViewModel model = DataContext as ScheduleTabViewModel;
            if (model != null)
            {
                HitachiServiceClient client = WCFClient.GetClient();
                client.GetScheduleDocCompleted += new EventHandler<GetScheduleDocCompletedEventArgs>(client_GetScheduleDocCompleted);
                client.GetScheduleDocAsync(model.CurrentServiceWeek + model.CurrentSelectedWeek, model.CurrentLine.Id);
            }
        }

        private void client_GetScheduleDocCompleted(object sender, GetScheduleDocCompletedEventArgs e)
        {
            String url = e.Result;
            System.Windows.Browser.HtmlPage.Window.Prompt(url);
            System.Windows.Browser.HtmlPage.Window.Navigate(new Uri(url), "_blank", "height=300,width=600,top=100,left=100");
        }

        private void week_tab_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ScheduleTabViewModel model = DataContext as ScheduleTabViewModel;
            if (model != null)
            {
                model.CurrentSelectedWeek = week_tab.SelectedIndex;
            }
        }
    }
}
